<template>
  <div class="user_container">
    <div class="user_header">
      <div class="left_info">
        <div class="user_img">
          <img :src="userInfo.avatar" alt="" />
        </div>
        <div class="user_info">
          <div class="th">
            <div class="nickname">{{ userInfo.nickname }}</div>
            <div class="vip">
              <img :src="userInfo.vip_icon" alt="" />{{ userInfo.vip_name }}
            </div>
          </div>
          <div class="td">
            ID:&nbsp;&nbsp;{{ userInfo.uid}}
            <i @click="goUserData"></i>
          </div>
        </div>
      </div>
      <div class="right_set">
        <img
          src="../../assets/icon/user/white_set.svg"
          alt=""
          @click="goUserData"
        />
      </div>
    </div>
    <div class="user_main">
      <div class="main_box">
        <div class="user_nav">
          <a class="nav_item"
            ><p class="ni">我的余额</p>
            <p class="count">{{ userInfo.now_money }}</p></a
          >
          <a class="nav_item"
            ><p class="ni">当前佣金</p>
            <p class="count">{{ userInfo.broken_commission }}</p></a
          >
          <a class="nav_item"
            ><p class="ni">优惠卷</p>
            <p class="count">{{ userInfo.birthday }}</p></a
          >
        </div>
        <div class="user_order">
          <div class="uo_td">
            <div class="uo_td_left">我的订单</div>
            <div class="uo_td_right" @click="goOrderList">全部订单<i> </i></div>
          </div>
          <div class="uo_dd">
            <a class="uo_dd_item" href="#/order/list/0">
              <img src="../../assets/icon/user/user_daihuan.png" alt="" />
              <p>代付款</p>
              <span class="icon" v-if="orderStatusNum.unpaid_count > 0">{{ orderStatusNum.unpaid_count }}</span>
            </a>
            <a class="uo_dd_item" href="#/order/list/1">
              <img src="../../assets/icon/user/user_daifa.png" alt="" />
              <p>待发货</p>
              <span class="icon" v-if="orderStatusNum.unshipped_count > 0">{{orderStatusNum.unshipped_count}}</span>
            </a>
            <a class="uo_dd_item" href="#/order/list/2">
              <img src="../../assets/icon/user/user_daishou.png" alt="" />
              <p>待收货</p>
              <span class="icon" v-if="orderStatusNum.received_count > 0">{{orderStatusNum.received_count}}</span>
            </a>
            <a class="uo_dd_item" href="#/order/list/3">
              <img src="../../assets/icon/user/user_daiping.png" alt="" />
              <p>代评价</p>
              <span class="icon" v-if="orderStatusNum.evaluated_count > 0">{{orderStatusNum.evaluated_count}}</span>
            </a>
            <a class="uo_dd_item" href="#/order/refund_list">
              <img src="../../assets/icon/user/user_shouhou.png" alt="" />
              <p>售后/退款</p>
              <span class="icon" v-if="orderStatusNum.refund_count > 0">{{ orderStatusNum.refund_count}}</span>
            </a>
          </div>
        </div>
        <div class="user_serve">
          <div class="us_td">
            <div class="uo_td_left">我的服务</div>
          </div>
          <div class="us_dd">
            <a 
            href="#/user/vip"
            class="us_dd_item" >
              <img src="../../assets/icon/user/tt_vip.png" alt="" />
              <p>会员中心</p>
            </a>
            <a 
            href="#/index"
            class="us_dd_item">
              <img src="../../assets/icon/user/tt_kanjia.png" alt="" />
              <p>砍价记录</p>
            </a>
            <a 
            href="#/user/user_promotion"
            class="us_dd_item">
              <img src="../../assets/icon/user/tt_wode.png" alt="" />
              <p>我的推广</p>
            </a>
            <a 
            href="#/user/account"
            class="us_dd_item" >
              <img src="../../assets/icon/user/tt_yue.png" alt="" />
              <p>我的余额</p>
            </a>
            <a 
            href="#/user/add_manage"
            class="us_dd_item">
              <img src="../../assets/icon/user/tt_dizhi.png" alt="" />
              <p>地址信息</p>
            </a>
            <a 
            href="#/collect"
            class="us_dd_item">
              <img src="../../assets/icon/user/tt_collect.png" alt="" />
              <p>我的收藏</p>
            </a>
            <a 
             href="#/index"
            class="us_dd_item">
              <img src="../../assets/icon/user/tt_dizhi.png" alt="" />
              <p>优惠劵</p>
            </a>
            <a 
             href="#/index"
            class="us_dd_item">
              <img src="../../assets/icon/user/tt_collect.png" alt="" />
              <p>联系客服</p>
            </a>
          </div>
        </div>

        <div class="exit_loginout" @click="loginOut1">退出登录</div>
      </div>
    </div>

    <!-- <h3>这是用户页</h3>
    <button @click="loginOut1">退出登录</button>
    <p>{{ token }}</p>
    <p>{{ userInfo.nickname }}</p> -->
  </div>
</template>

<script>
import { getUser } from "@/utils/user.js";
import { mapGetters, mapMutations, mapState } from "vuex";
import { Toast } from 'vant'
export default {
  name: "User",
  data() {
    return {
      userInfo: {},
      orderStatusNum:{},
    };
  },
  computed: {
    ...mapState("login", ["token"]),
    ...mapGetters("login", ["loginUserInfo"]),
  },
  created() {
    getUser().then((res) => {
      console.log(res.data);
      this.userInfo = res.data.data;
      this.orderStatusNum = res.data.data.orderStatusNum
    });
  },
  methods: {
    ...mapMutations("login", ["loginOut"]),
    // 退出登录函数
    loginOut1() {
      // 在mutations里改
      this.loginOut();
      Toast('退出登录');
      this.$router.push("/index");
    },

    //
    goUserData() {
      this.$router.push("/user/data");
    },
    goUserVip() {
      this.$router.push("/user/vip");
    },

    goUserAccount() {
      this.$router.push("/user/account");
    },
    goOrderList(){
      this.$router.push("/order/list/0")
    }
  },
};
</script>

<style lang="scss" scoped>
.user_container {
  padding-bottom: 70px;
}
.user_header {
  height: 125px;
  background-color: #e93323;
  border-bottom-left-radius: 20px;
  border-bottom-right-radius: 20px;
  padding: 20px 15px 0 15px;
  display: flex;
  justify-content: space-between;
  .left_info {
    width: 330px;
    display: flex;
    .user_img {
      width: 50px;
      height: 50px;
      border-radius: 50%;
      border: 1px solid #fff;
      > img {
        width: 100%;
        height: 100%;
        border-radius: 50%;
      }
    }

    .user_info {
      flex: 1;
      margin-left: 15px;
      .th {
        height: 30px;

        display: flex;
        align-items: center;
        .nickname {
          color: #fff;
          font-size: 16px;
        }
        .vip {
          margin-left: 13px;

          color: #fff;
          font-size: 13px;
          height: 20px;
          line-height: 20px;
          padding: 0 7px;
          background-color: rgba(0, 0, 0, 0.5);
          border-radius: 10px;
          > img {
            display: inline-block;
            width: 13px;
            height: 13px;
            // background-color: pink;
            vertical-align: middle;
            margin-right: 2px;
            margin-top: -1px;
          }
        }
      }

      .td {
        color: #cccc;
        font-size: 14px;
        i {
          display: inline-block;
          width: 13px;
          height: 13px;
          background-color: #ccc;
          background: url(../../assets/icon/user/cccc_edit.svg) no-repeat;
          background-size: 100% 100%;
          vertical-align: middle;
          margin-left: 8px;
        }
      }
    }
  }

  .right_set {
    > img {
      width: 20px;
      height: 20px;
    }
  }
}
.user_main {
  width: 100%;
  padding: 0 10px;
  margin-top: -36px;
  .user_nav {
    border-radius: 8px;
    height: 70px;
    background-color: #fff;
    display: flex;
    align-items: center;
    .nav_item {
      display: block;
      flex: 1;
      p {
        text-align: center;
      }
      .ni {
        font-size: 14px;
        color: #aaa;
      }
      .count {
        margin-top: 3px;
        color: #282828;
        font-size: 17px;
      }
    }
    .nav_item:nth-child(2) {
      border-right: 1px solid #eee;
      border-left: 1px solid #eee;
    }
  }
  .user_order {
    background-color: #fff;
    border-radius: 8px;
    margin: 10px 0;
    .uo_td {
      height: 40px;
      line-height: 40px;
      display: flex;
      justify-content: space-between;
      font-size: 16px;
      padding: 0 15px;
      .uo_td_left {
        color: #282828;
      }
      .uo_td_right {
        font-size: 14px;
        color: #666;
        position: relative;
        padding-right: 12px;

        i {
          position: absolute;
          width: 20px;
          height: 20px;
          top: 50%;
          right: 0px;
          margin-top: -10px;
          display: inline-block;
          background: url(../../assets/icon/common/right_arrow.svg) no-repeat;
          background-size: 100% 100%;
        }
      }
    }

    .uo_dd {
      display: flex;
      // height: 80px;
      .uo_dd_item {
        flex: 1;
        display: block;

        text-align: center;
        height: 80px;
        padding-top: 10px;
        position: relative;
        > img {
          width: 30px;
        }
        > p {
          text-align: center;
          color: #454545;
          font-size: 14px;
          // margin-top: 5px;
        }
        > .icon {
          position: absolute;
          top: 5px;
          right: 14px;
          z-index: 1000;      
          background-color: #fff;
          color: #ee5a52;
          border-radius: 15px;
          padding: 0px 4px;
          font-size: 12px;             
          border: 1px solid #ee5a52;
          text-align: right;
        }
      }
    }
  }
  .user_serve {
    background-color: #fff;
    border-radius: 8px;
    .us_td {
      height: 40px;
      line-height: 40px;
      display: flex;
      justify-content: space-between;
      font-size: 16px;
      padding: 0 15px;
    }
    .us_dd {
      padding: 0px 0 18px 0;
      display: flex;
      flex-wrap: wrap;
      .us_dd_item {
        flex: 25%;
        margin-top: 15px;
        text-align: center;
        > img {
          width: 26px;
        }
        > p {
          text-align: center;
          font-size: 14px;
          color: #333;
        }
      }
    }
  }
  .exit_loginout {
    margin: 25px auto 0;
    width: 100px;
    height: 40px;
    font-size: 16px;
    border-radius: 4px;
    background-color: #f50;
    color: #fff;
    text-align: center;
    line-height: 40px;
  }
}
</style>
